package com.demo;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Graph {


    private Map<String, Set<String>> adjacencyMap;

    public Graph() {
        adjacencyMap = new HashMap<>();
    }

    public void addNode(String node) {
        adjacencyMap.put(node, new HashSet<>());
    }

    public void addEdge(String node1, String node2) {
        if (adjacencyMap.containsKey(node1) && adjacencyMap.containsKey(node2)) {
            adjacencyMap.get(node1).add(node2);
           // adjacencyMap.get(node2).add(node1);
            }
    }

    public Set<String> getNeighbors(String node) {
        return adjacencyMap.getOrDefault(node, new HashSet<>());
    }

    public boolean hasNode(String node) {
        return adjacencyMap.containsKey(node);
    }

    public boolean hasEdge(String node1, String node2) {
        return adjacencyMap.containsKey(node1) && adjacencyMap.get(node1).contains(node2);
    }
}

